package com.seari.groovyrunner.schedule;

import com.seari.groovyrunner.service.impl.GroovyLogServiceImpl;
import com.seari.groovyrunner.utils.SpringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.Date;

@Component
public class GroovySchedule {

    @Scheduled(cron = "0 0 0 * * ?")
    public static void schedule() {
        System.out.println("定时任务启动 -- 清理一周前记录" );
        GroovyLogServiceImpl groovyLogMapper = SpringUtils.getBean("GroovyLogServiceImpl");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(System.currentTimeMillis()));
        calendar.add(Calendar.DAY_OF_MONTH, -7);
        groovyLogMapper.deleteGroovyLogByTime(calendar.getTimeInMillis());
        System.out.println("定时任务结束" );
    }
}
